package com.szd.qiongyou20.home.adapter;

import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.szd.qiongyou20.R;

import java.util.List;

/**
 * Created by SZD on 2016/12/6.
 */

public class ViewPager_City_Adapter extends PagerAdapter {

    private Context mContext;
    private List<String> mList;
    private LayoutInflater mInflater;

    public ViewPager_City_Adapter(Context context, List<String> list) {
        mContext = context;
        mList = list;
        mInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }

    @Override
    public int getCount() {
        return mList.size();
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == object;
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        View view = mInflater.inflate(R.layout.item_city_viewpager, container, false);
        ImageView imageView = (ImageView) view.findViewById(R.id.imageView_city_viewPager);
        // 获取图片的链接地址
        String pic_url = mList.get(position);
        Log.i("图片的地址", "instantiateItem: " + mList.get(position));

        Glide.with(mContext).load(pic_url).into(imageView);
        // 获取点击事件的链接地址
        container.addView(view);
        return view;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
//        super.destroyItem(container, position, object);
        container.removeView((View) object);
    }
}
